import React from 'react';

import BaseExecuter from '../common/BaseExecuter';
import Constants from '../../common/Constants';

import DataManager from '../../datas/DataManager';

export default class UserExecuter extends BaseExecuter {
  execute(action) {
    switch (action.name) {
      case "GetSelfDataAction":
        this._getUserData(action);
        break;
      case "UserRequestPostAction":
        this._requestPost(action);
        break;
      case "UserRequestSelfDataAction":
        this._requestSelfData(action);
        break;
      case "UserUpdatePasswordAction":
        this._requestUpdatePassword(action);
        break;
      case "UserUpdateSelfDataAction":
        this._sendUpdateSelfData(action);
        break;
      case "UserRequestAPPConfigAction":
        this._requestAppConfig(action);
        break;
      case "UserRequestOtherDataAction":
        this._requestOtherUserData(action);
        break;
      case "UserForgetPwdAction":
        this._requestForgetPwd(action);
        break;
      case "UserUpdatePhoneAction":
        this._requestUpdatePhone(action);
        break;
      case "UserRequestNoticeListAction":
        this._requestNoticeList(action);
        break;
      case "UserRequestSaerchListAction":
        this._requestSaerchList(action);
        break;
      case "NoticeMsgSystemNumAction":
        this._requestMsgSystem(action);
        break;
      case "NoticeMsgCommentsAction":
        this._requestMsgComments(action);
        break;
      default:
    }
  }

  _requestMsgSystem(action){
    this._sendRequestCommonResponse(action, "requestMsgSystem");
  }
  _requestMsgComments(action){
    this._sendRequestCommonResponse(action, "requestMsgComments");
  }
  _requestNoticeList(action) {
    this._sendRequestCommonResponse(action, "requestNoticeList");
  }
  _requestSaerchList(action) {
    this._sendRequestCommonResponse(action, "requestSaerchList");
  }

  _requestOtherUserData(action) {
    this._sendRequestCommonResponse(action, "requestOtherUserData");
  }

  _requestAppConfig(action) {
    this._sendRequestCommonResponse(action, "requestAppConfig");
  }

  _requestUpdatePassword(action) {
    this._sendRequestCommonResponse(action, "sendUpdatePassword");
  }

  _requestForgetPwd(action) {
    this._sendRequestCommonResponse(action, "sendForgetPwd");
  }
  _requestUpdatePhone(action) {
    this._sendRequestCommonResponse(action, "sendUpdatePhone");
  }
  _requestSelfData(action) {
    DataManager.callMethod(Constants.MODULE_TYPE.USER,
      "sendRequestSelfData",
      [(data, isSucceed, response)=>{action.finish(data, isSucceed, response, this._requestSelfDataFinishCallback.bind(this))}]);
  }

  _requestSelfDataFinishCallback(UserData) {
    DataManager.callMethod(Constants.MODULE_TYPE.USER, "setUserData", [UserData]);
  }

  _requestPost(action) {
    let method = "";
    if(action.data.type == "dianzan"||action.data.type == "shoucang") {
      method = "sendRequestDianzanPosts";
      if(action.data.type == "shoucang") {
        method = "sendRequestShoucangPosts";
      }
      DataManager.callMethod(Constants.MODULE_TYPE.USER,
      method,
      [action.data, (data, isSucceed)=>{action.finish(data, isSucceed)}]);
    }else{
      if(action.data.type == "fabu") {
        method = "sendRequestFabuPosts";
      }

    DataManager.callMethod(Constants.MODULE_TYPE.USER,
      method,
      [action.data.page, (data, isSucceed)=>{action.finish(data, isSucceed)}]);
    }
    
  }

  _getUserData(action) {
    var data = DataManager.callMethod(Constants.MODULE_TYPE.USER,
      "getSelfData");
    action.finish(data);
  }

   _sendUpdateSelfData(action) {
    DataManager.callMethod(Constants.MODULE_TYPE.USER,
      "sendUpdateSelfData",
      [action.data, (data, isSucceed, response)=>{action.finish(data, isSucceed, response, this._requestSelfDataFinishCallback.bind(this))}]);
  }

  _getModuleType() {
    return Constants.MODULE_TYPE.USER;
  }
}
